Imports System.Diagnostics
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Data
Imports Alerts

Partial Class Pages_Clanky
    Inherits BasePage

    Private alert As Alerts = New Alerts
    Private _pocetOdberatelu As Integer
    Public Property pocetOdberatelu() As Integer
        Get
            Dim tableKontakty As DataView = CType(DS_Kontakty.Select(DataSourceSelectArguments.Empty), DataView)
            _pocetOdberatelu = tableKontakty.Table.Rows.Count
            Return _pocetOdberatelu
        End Get
        Set(ByVal value As Integer)
            _pocetOdberatelu = value
        End Set
    End Property

    Protected Sub FV_kontakt_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles FV_kontakt.ItemInserted
        Dim Msg As New MailMessage()
        Dim adresat As MailAddress = New MailAddress(CType(FV_kontakt.FindControl("TXB_mail"), TextBox).Text)
        Dim Senderx As New SmtpClient()

        If e.Exception Is Nothing Then

            If e.AffectedRows = 1 Then
                alert.Show(GetLocalResourceObject("alert_registrationOK").ToString, GetLocalResourceObject("title_registration").ToString)

                'Potvrzeni registrace mailem
                Msg.From = New MailAddress("zpravodaj@horejsi.cz", "Zpravodaj")
                Msg.Subject = GetLocalResourceObject("title_registration").ToString

                Msg.Body = GetLocalResourceObject("alert_registrationOK").ToString
                Msg.To.Add(adresat)
                Msg.Bcc.Add(New MailAddress("info@horejsi.cz"))
                Senderx.Send(Msg)
                lbl_PocetOdberatelu.Text = GetLocalResourceObject("lbl_countSubs").ToString + pocetOdberatelu.ToString
            Else
                alert.Show(GetLocalResourceObject("alert_errorDB").ToString, GetLocalResourceObject("title_registration").ToString)

            End If

        Else
            e.ExceptionHandled = True
            e.KeepInInsertMode = True
            alert.Show(String.Format(GetLocalResourceObject("alert_errorDuplicate").ToString, adresat.Address), GetLocalResourceObject("title_registration").ToString)

        End If


    End Sub


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load




        If Not IsPostBack Then
            lbl_PocetOdberatelu.Text = GetLocalResourceObject("lbl_countSubs").ToString + pocetOdberatelu.ToString
        End If
    End Sub

    'Protected Sub GV_Zpravodaj_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GV_Zpravodaj.DataBound
    '    'Zobrazeni poctu zaznamu
    '    Dim datavi As DataView = CType(DS_Zpravodaj.Select(DataSourceSelectArguments.Empty), DataView)
    '    Dim Rozsah As Integer
    '    Dim DolniPocet As Integer
    '    Dim HorniPocet As Integer

    '    'DolniPocet = (GV_Zpravodaj.PageIndex * GV_Zpravodaj.PageSize) + 1
    '    'HorniPocet = (GV_Zpravodaj.PageIndex + 1) * GV_Zpravodaj.PageSize
    '    'Rozsah = datavi.Table.Rows.Count
    '    'If HorniPocet > Rozsah Then HorniPocet = Rozsah



    'End Sub

   

End Class
